#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace PHMEE.EnergyEfficiency;

public enum LogAbstractEventType
{
    [Description("Arrival")]
    Arrival = 1,
    
    [Description("Arrival (EU)")]
    ArrivalEU = 2,
    
    [Description("Arrival (STS)")]
    ArrivalSTS = 3,
    
    [Description("Departure")]
    Departure = 4,
    
    [Description("Departure (EU)")]
    DepartureEU = 5,
    
    [Description("Departure (STS)")]
    DepartureSTS = 6,
    
    // [Description("Begin of offhire")]
    // BeginOfOffhire = 7,
    //
    // [Description("End of offhire")]
    // EndOfOffhire = 8,
    
    [Description("STS")]
    STS = 9,
    
    [Description("Year end")]
    YearEnd = 10,
    
    [Description("Voyage adjustment start")]
    VoyageAdjustmentStart = 11,
    
    [Description("Voyage adjustment over")]
    VoyageAdjustmentOver = 12,
    
    [Description("Noon (Position) - Sea passage")]
    NoonPositionSeaPassage = 13,
    
    [Description("Noon (Position) - Port")]
    NoonPositionPort = 14,
    
    [Description("Noon (Position) - Anchoring")]
    NoonPositionAnchoring = 15,
    
    [Description("COSP")]
    COSP = 16,
    
    [Description("EOSP")]
    EOSP = 17,
    
    [Description("Begin Anchoring/Drifting")]
    BeginAnchoringOrDrifting = 18,
    
    [Description("End Anchoring/Drifting")]
    EndAnchoringOrDrifting = 19
}

public static class LogAbstractEventTypeHelper
{
    /// <summary>
    /// 离港事件（用于识别航次，非常重要）
    /// </summary>
    public static readonly List<LogAbstractEventType> DepartureEvents =
    [
        LogAbstractEventType.Departure,
        LogAbstractEventType.DepartureEU,
        // LogAbstractEventType.DepartureSTS
    ];
    
    /// <summary>
    /// 到港事件
    /// </summary>
    public static readonly List<LogAbstractEventType> ArrivalEvents =
    [
        LogAbstractEventType.Arrival,
        LogAbstractEventType.ArrivalEU,
        // LogAbstractEventType.ArrivalSTS
    ];
    
    /// <summary>
    /// 不包含 EU 的到港事件
    /// </summary>
    public static readonly HashSet<LogAbstractEventType> ArrivalEventsWithoutEU =
    [
        LogAbstractEventType.Arrival,
        LogAbstractEventType.ArrivalSTS
    ];
    
    /// <summary>
    /// 调整事件
    /// </summary>
    public static readonly List<LogAbstractEventType> AdjustmentEvents =
    [
        LogAbstractEventType.VoyageAdjustmentStart,
        LogAbstractEventType.VoyageAdjustmentOver
    ];
    
    /// <summary>
    /// STS 作业相关的事件
    /// </summary>
    public static readonly List<LogAbstractEventType> STSEvents =
    [
        LogAbstractEventType.ArrivalSTS,
        LogAbstractEventType.STS,
        LogAbstractEventType.DepartureSTS
    ];

    /// <summary>
    /// 获取 departureEvent 对应的 arrivalEvent
    /// </summary>
    /// <param name="departureEvent"></param>
    /// <returns></returns>
    /// <exception cref="Exception"></exception>
    [Obsolete("航次逻辑发生了调整，改为（“离港”到“离港”】，所以已经不该再使用")]
    public static List<LogAbstractEventType> GetPairedArrivalEvents(LogAbstractEventType departureEvent)
    {
        return departureEvent switch
        {
            LogAbstractEventType.Departure or LogAbstractEventType.DepartureEU =>
            [
                LogAbstractEventType.Arrival,
                LogAbstractEventType.ArrivalEU
            ],
            LogAbstractEventType.DepartureSTS => [LogAbstractEventType.ArrivalSTS],
            _ => throw new Exception("Unrecognized departureEvent")
        };
    }
}